package com.ccloud.blog.modules.blog.controller;

import com.ccloud.blog.modules.blog.service.IBlogTagService;
import com.ccloud.common.core.reqres.response.R;
import com.ccloud.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author chentl
 * @version V1.0
 * @Project BlogTagController
 * @Title BlogTagController.java
 * @Description blog 控制器
 * @Package com.echo.blog.business.blog.controller
 * @date 2019/9/5 18:03
 * @Copyright: 上海顺益信息科技有限公司 All rights reserved.
 */
@RestController
@Slf4j
@RequestMapping("/blogTag")
public class BlogTagController {

    @Resource
    private IBlogTagService blogTagService;

    @RequestMapping(value = "/list")
    public R getBlogList() {
        List<Map<String, Object>> list = blogTagService.getBloyTagList();
        return R.ok(list, "成功");
    }

    @RequestMapping(value = "/add")
    public R add(String tagName) {
        if (StringUtils.isBlank(tagName)) {
            return R.fail("tagName不能为空!");
        }
        //添加博客标签
        blogTagService.insertBlogTagByName(tagName);

        List<Map<String, Object>> list = blogTagService.getBloyTagList();
        return R.ok(list, "成功");
    }


}
